//
//  LoginQueryLogisticsV.swift
//  swiftProject
//
//  Created by ZhangSai on 2021/5/12.
//

import UIKit

class LoginQueryLogisticsV: UIView {

    typealias QueryLogisticsBlock = () -> Void
    var queryLogisticsBlock : QueryLogisticsBlock!
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        self.addSubview(self.leftLine)
        self.addSubview(self.rightLine)
        self.addSubview(self.titleLab)
        self.addSubview(self.importTF)
        self.addSubview(self.placeholderImg)
        
        self.titleLab.snp.makeConstraints { (make) in
            make.centerX.equalTo(self.snp.centerX)
            make.width.lessThanOrEqualTo(200)
            make.top.equalTo(self.snp.top).offset(0)
        }
        self.leftLine.snp.makeConstraints { (make) in
            make.left.equalTo(self.snp.left).offset(0)
            make.right.equalTo(self.titleLab.snp.left).offset(-10)
            make.height.equalTo(1)
            make.centerY.equalTo(self.titleLab.snp.centerY)
        }
        self.rightLine.snp.makeConstraints { (make) in
            make.right.equalTo(self.snp.right).offset(0)
            make.left.equalTo(self.titleLab.snp.right).offset(10)
            make.height.equalTo(1)
            make.centerY.equalTo(self.titleLab.snp.centerY)
        }
        self.importTF.snp.makeConstraints { (make) in
            make.top.equalTo(self.titleLab.snp.bottom).offset(30)
            make.left.equalTo(self.snp.left).offset(0)
            make.right.equalTo(self.snp.right).offset(0)
            make.height.equalTo(34)
        }
        self.placeholderImg.snp.makeConstraints { (make) in
            make.top.equalTo(self.importTF.snp.top).offset(0)
            make.right.equalTo(self.importTF.snp.right).offset(0)
            make.bottom.equalTo(self.importTF.snp.bottom).offset(0)
            make.width.equalTo(self.placeholderImg.snp.height)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    @objc func quertRecord () {
        if (queryLogisticsBlock != nil) {
            queryLogisticsBlock()
        }
    }
    
    func refreshUI(index:Int) {
        self.titleLab.text = ZslanguageTool.sharedLanguageTool().getIanguageWithKey(key: LanguageHeader.WL_Tracking)
        self.importTF.placeholder = ZslanguageTool.sharedLanguageTool().getIanguageWithKey(key: LanguageHeader.hint_import_MailNoQnum)
    }
    
    lazy var leftLine:UIView = {
        let leftLine = UIView()
        leftLine.backgroundColor = UIColor.init(hexString: "#D8D8D8");
        return leftLine
    }()
    lazy var rightLine:UIView = {
        let rightLine = UIView()
        rightLine.backgroundColor = UIColor.init(hexString: "#D8D8D8");
        return rightLine
    }()
    lazy var titleLab:UILabel = {
        let titleLab = UILabel()
        titleLab.textColor = UIColor.init(hexString: "#717171");
        titleLab.font = UIFont.systemFont(ofSize: 17)
        titleLab.text = ZslanguageTool.sharedLanguageTool().getIanguageWithKey(key: LanguageHeader.WL_Tracking)

        return titleLab
    }()
    lazy var importTF:UITextField = {
        let importTF = UITextField()
        importTF.font = UIFont.systemFont(ofSize: 14)
        importTF.keyboardType = UIKeyboardType.asciiCapable
        importTF.borderStyle = .roundedRect
        importTF.textAlignment = .left
        importTF.backgroundColor = UIColor.white
        importTF.clearButtonMode = .always
        importTF.placeholder = ZslanguageTool.sharedLanguageTool().getIanguageWithKey(key: LanguageHeader.hint_import_MailNoQnum)
        importTF.layer.borderColor = UIColor.init(hexString: "#979797").cgColor
        importTF.layer.borderWidth = 1
        let leftView:UIView = UIView.init(frame: CGRect.init(x: 0, y: 0, width: 34, height: 34))
        let leftImage:UIImageView = UIImageView.init(image: UIImage.init(named: "login_FeldLeft"))
        leftImage.frame = CGRect.init(x: 10, y: (34-20)/2, width: 20, height: 20)
        leftView.addSubview(leftImage)
        importTF.leftView = leftView
        importTF.leftViewMode = .always
        return importTF
    }()
    lazy var placeholderImg:UIImageView = {
        let placeholderImg = UIImageView()
        placeholderImg.image = UIImage.init(named: "login_FeldRight")
        let tap:UITapGestureRecognizer = UITapGestureRecognizer.init(target: self, action: #selector(quertRecord))
        placeholderImg.addGestureRecognizer(tap)
        placeholderImg.isUserInteractionEnabled = true
        
        return placeholderImg
    }()
}
